home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_217 / stevie / mark.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  133 lines

  1. /*
  2.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  3.  *
  4.  * Code Contributions By : Tim Thompson           twitch!tjt
  5.  *                         Tony Andrews           onecom!wldrdg!tony 
  6.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  7.  */
  8.  
  9. #include "stevie.h"
  10.  
  11. #ifdef  MEGAMAX
  12. overlay "mark"
  13. #endif
  14.  
  15. /*
  16.  * This file contains routines to maintain and manipulate marks. 
  17.  */
  18.  
  19. #define NMARKS  10        /* max. # of marks that can be saved */
  20.  
  21. struct mark {
  22.     char            name;
  23.     LPtr            pos;
  24. };
  25.  
  26. static struct mark mlist[NMARKS];
  27. static struct mark pcmark;    /* previous context mark */
  28. static bool_t   pcvalid = FALSE;/* true if pcmark is valid */
  29.  
  30. /*
  31.  * setmark(c) - set mark 'c' at current cursor position 
  32.  *
  33.  * Returns TRUE on success, FALSE if no room for mark or bad name given. 
  34.  */
  35. bool_t
  36. setmark(c)
  37.     char            c;
  38. {
  39.     int             i;
  40.  
  41.     if (!isalpha(c))
  42.     return FALSE;
  43.  
  44.     /*
  45.      * If there is already a mark of this name, then just use the existing
  46.      * mark entry. 
  47.      */
  48.     for (i = 0; i < NMARKS; i++) {
  49.     if (mlist[i].name == c) {
  50.         mlist[i].pos = *Curschar;
  51.         return TRUE;
  52.     }
  53.     }
  54.  
  55.     /*
  56.      * There wasn't a mark of the given name, so find a free slot 
  57.      */
  58.     for (i = 0; i < NMARKS; i++) {
  59.     if (mlist[i].name == NUL) {    /* got a free one */
  60.         mlist[i].name = c;
  61.         mlist[i].pos = *Curschar;
  62.         return TRUE;
  63.     }
  64.     }
  65.     return FALSE;
  66. }
  67.  
  68. /*
  69.  * setpcmark() - set the previous context mark to the current position 
  70.  */
  71. void
  72. setpcmark()
  73. {
  74.     pcmark.pos = *Curschar;
  75.     pcvalid = TRUE;
  76. }
  77.  
  78. /*
  79.  * getmark(c) - find mark for char 'c' 
  80.  *
  81.  * Return pointer to LPtr or NULL if no such mark. 
  82.  */
  83. LPtr           *
  84. getmark(c)
  85.     char            c;
  86. {
  87.     int             i;
  88.  
  89.     if (c == '\'' || c == '`')    /* previous context mark */
  90.     return pcvalid ? &(pcmark.pos) : (LPtr *) NULL;
  91.  
  92.     for (i = 0; i < NMARKS; i++) {
  93.     if (mlist[i].name == c)
  94.         return &(mlist[i].pos);
  95.     }
  96.     return (LPtr *) NULL;
  97. }
  98.  
  99. /*
  100.  * clrall() - clear all marks 
  101.  *
  102.  * Used mainly when trashing the entire buffer during ":e" type commands 
  103.  */
  104. void
  105. clrall()
  106. {
  107.     int             i;
  108.  
  109.     for (i = 0; i < NMARKS; i++)
  110.     mlist[i].name = NUL;
  111.     pcvalid = FALSE;
  112. }
  113.  
  114. /*
  115.  * clrmark(line) - clear any marks for 'line' 
  116.  *
  117.  * Used any time a line is deleted so we don't have marks pointing to
  118.  * non-existent lines. 
  119.  */
  120. void
  121. clrmark(line)
  122.     LINE           *line;
  123. {
  124.     int             i;
  125.  
  126.     for (i = 0; i < NMARKS; i++) {
  127.     if (mlist[i].pos.linep == line)
  128.         mlist[i].name = NUL;
  129.     }
  130.     if (pcvalid && (pcmark.pos.linep == line))
  131.     pcvalid = FALSE;
  132. }
  133.